<?
require("config.php");

$show_backnav = "product_menu";
$location_status .= "| Edit";

$menuname = array(
	"Info",
	"Pictures",
/*	"Color",
	"Size",
	"Specification",
	"Features",
	"Accessories",
	"Packaging",*/
);

$menutarget = array(
	"edit",
	"edit_pictures",
/*	"edit_color",
	"edit_size",
	"edit_specification",
	"edit_features",
	"edit_accessories",
	"edit_packaging",*/
);

$menutype = 2;

if (NULL!=$action){

	$query = "select parent from pro_category where id='$Category'";
	$r = myQuery($query);

	$Parent = $r[0][0];
	$issue=mktime(0,0,0,$mm,$dd,$yyyy);
	$updatetime=mktime(0,0,0,$umm,$udd,$uyyyy);
	if (!$hideweight) $hideweight=0;

   $field = array(
	"code",
	"name",
	"description",
	"unit",
	"brand",
	"type",
	"category",
	"fabric",
	"price_euro",
	"price_gbp",
	"price_hkd",
	"price_usd",
	"remark",
	"parent_category",
	"auth",
	"mark_new",
	"publish",
	"weight",
	"reorder",
	"stock",
	"issuedate",
	"sn_en",
	"sn_cn",
	"updatetime",
	"hideweight"
	);


   $content = array(
	$Code,
	$Name,
	$Description,
	$Unit,
	$CName,
	$Type,
	$Category,
	$Fabric,
	$Euro,
	$Gbp,
	$Hkd,
	$Usd,
	$CDescription,
	$Parent,
	$Auth,
	$Mark_new,
	$Publish,
	$weight,
	$reorder,
	$stock,
	$issue,
	$sn_en,
	$sn_cn,
	$updatetime,
	$hideweight
	);
	
   $exp = "id=$id";

   myUpdate($table,$field,$content,$exp);


   header("location:edit_info.php?id=$id&target=edit_pictures&a=0&Start_Num=" . $Start_Num."&cat=".$cat);

   exit();

}


if (!checkRecord($table,$id)){

	header("location:" . $rela_path . "share/msg.php?v=9002");
  
}

$Query = "select 
	code,
	name,
	description,
	unit,
	brand,
	type,
	category,
	fabric,
	price_euro,
	price_gbp,
	price_hkd,
	price_usd,
	remark,
	auth,
	size,
	mark_new,
	publish ,
	weight,
	reorder,
	stock,
	issuedate,
	sn_en,
	sn_cn,
	updatetime,
	hideweight
from pro_basic where id=$id Limit 1";

$r = myQuery($Query);

$Code=$r[0][0];
$Name=$r[0][1];
$Description=$r[0][2];
$Unit=$r[0][3];
$CName=$r[0][4];
$Type=$r[0][5];
$Category=$r[0][6];
$Fabric=$r[0][7];
$Price_euro=$r[0][8];
$Price_gbp=$r[0][9];
$Price_hkd=$r[0][10];
$Price_usd=$r[0][11];
$CDescription =$r[0][12];
$Auth =$r[0][13];
$Size =$r[0][14];
$Mark_new =$r[0][15];
$Publish =$r[0][16];
$weight =$r[0][17];
$reorder =$r[0][18];
$stock =$r[0][19];
$issue =$r[0][20];
$sn_en = $r[0][21];
$sn_cn = $r[0][22];
$updatetime = $r[0][23];
$hideweight = $r[0][24];

$Query = "select code, name from pro_brand";
$brands = myQuery($Query);

$Query = "select code, name from pro_type";
$types = myQuery($Query);


$Query = "select code, name from pro_category";
$categorys = myQuery($Query);


if ($issue < strtotime('1980-01-01 00:00:00')) {
	$da='';
	$mo='';
	$ye='';
}
else {
	$da=date('d',$issue);
	$mo=date('m',$issue);
	$ye=date('Y',$issue);
}

if ($updatetime < strtotime('1980-01-01 00:00:00')) {
	$uda='';
	$umo='';
	$uye='';
}
else {
	$uda=date('d',$updatetime);
	$umo=date('m',$updatetime);
	$uye=date('Y',$updatetime);
}



require($rela_path . "inc/header.php");
function inputDate($dd,$mm,$yyyy,$prefix='') {
	$html='<select name="'.$prefix.'dd"><option value="">--</option>';
	for ($i=1;$i<=31;$i++) {
		if ($dd==$i) $s=' selected';
		else $s='';
		$html.='<option value="'.$i.'"'.$s.'>'.$i.'</option>';
	}
	$html.='</select> - <select name="'.$prefix.'mm"><option value="">--</option>';
	for ($i=1;$i<=12;$i++) {
		if ($mm==$i) $s=' selected';
		else $s='';
		$html.='<option value="'.$i.'"'.$s.'>'.$i.'</option>';
	}
	$html.='</select> - <select name="'.$prefix.'yyyy"><option value="">----</option>';
	for ($i=1980;$i<=2013;$i++) {
		if ($yyyy==$i) $s=' selected';
		else $s='';
		$html.='<option value="'.$i.'"'.$s.'>'.$i.'</option>';
	}
	$html.='</select>';
	
	return $html;
}

?>

<!--Content Start-->
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getName(variable) {
	var a = new Array();
	var b = new Array();

	a[0]='Name';
	a[1]='CName';
	a[2]='weight';
	a[3]='reorder';
	a[4]='stock';
	a[5]='Euro';
	a[6]='Gbp';
	a[7]='Hkd';
	a[8]='Usd';

	b[0]='English Name';
	b[1]='Chinese Name';
	b[2]='Weight';
	b[3]='Current reorder level';
	b[4]='Current stock level';
	b[5]='Normal Price';
	b[6]='Special Price';
	b[7]='Member Price';
	b[8]='VIP Price';
	
	for (i=0;i<a.length;i++) {
		if (a[i]==variable) return b[i];
		//alert(a[i]+b[i]);
	}
	return variable;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+getName(nm)+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+getName(nm)+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+getName(nm)+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+getName(nm)+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>

<form action="" method="post" name="form1">                    <table width="95%" border="0" align="center">
                      <tr> 
      <td align="right">
	  
	  <input type="image" src="../../images/bt_cancel.gif" width="78" height="23" onclick="Redirect('product_menu.php?Start_Num=<?=$Start_Num?>',1);return false;"> 
      <input name="image2" type="image" onClick="MM_validateForm('Code','','R','Name','','R','CName','','R','weight','','RisNum','reorder','','NisNum','stock','','NisNum','Euro','','RisNum','Gbp','','NisNum','Hkd','','NisNum','Usd','','NisNum');return document.MM_returnValue" src="../../images/bt_save.gif" width="76" height="22">
</td>
                      </tr>
                    </table>
                    <table width="95%" border="0" align="center">
                      <tr> 
                        <td align="right">&nbsp; </td>
                      </tr>
                      <tr> 
                        <td><table border="0" cellspacing="0" cellpadding="2">
                          <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><div align="center"><strong>English</strong></div></td>
                            <td><div align="center"><strong> Chinese </strong></div></td>
                          </tr>
                          <tr>
                            <td>Code :</td>
                            <td><input type="text" class="text" name="Code" value="<?print($Code)?>" >
                                <!--hidden filed-->
                                <input name="action" type="hidden" value="add">
                                
                            </td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Publish:</td>
                            <td><?
$sourceData = array(
1,
0,
);

$sourceLabel = array(
"Yes",
"No",

);

$boxName = "Publish";

FFPRadioBox($boxName,$Publish,$sourceData,$sourceLabel);


?>
                            </td>
                            <td>&nbsp;</td>
                          </tr>
        <tr> 
          <td>New Item ? </td>
          <td>
<?
$sourceData = array(
1,
0,
);

$sourceLabel = array(
"Yes",
"No",
);

$boxName = "Mark_new";

FFPRadioBox($boxName,$Mark_new,$sourceData,$sourceLabel);


?>

</td>
        </tr>

        <tr> 
          <td>Promotional Item ?</td>
          <td>
<?
$sourceData = array(
1,
0,
);

$sourceLabel = array(
"Yes",
"No",

);

$boxName = "Auth";

$value = $Auth;

FFPRadioBox($boxName,$value,$sourceData,$sourceLabel);


?>

</td>
        </tr>
                          <tr>
                            <td>Name :</td>
                            <td><input name="Name" type="text" class="text" value="<?print($Name)?>" size="50" <?print($active)?>="<?print($active)?>">
                            </td>
                            <td><input name="CName" type="text" class="text" id="CName" value="<?print($CName)?>" size="50" <?print($active)?>="<?print($active)?>"></td>
                          </tr>
                          <tr>
                            <td>Description :</td>
                            <td><textarea class="text" name="Description" cols="50" rows="12"  <?print($active)?>><?print($Description)?></textarea>
                            </td>
                            <td><textarea name="CDescription" cols="50" rows="12" class="text" id="CDescription"  <?print($active)?>><?print($CDescription)?></textarea></td>
                          </tr>
                            <tr> 
                              <td>Special Note :</td>
                              <td> <textarea name="sn_en" cols="50" rows="5" class="text" id="sn_en"  <?print($active)?>><?print($sn_en)?></textarea> 
                              </td>
                              <td><textarea name="sn_cn" cols="50" rows="5" class="text" id="sn_cn"  <?print($active)?>><?print($sn_cn)?></textarea></td>
                            </tr>
                          <tr>
                            <td>Category :</td>
                            <td><?

$boxName="Category";

$tb = "pro_category";

$Query = "select name,id from $tb WHERE level=0 order by id";
$r = myQuery($Query);

$Query = "select name, parent,id from $tb WHERE level=1 order by id";
$r1 = myQuery($Query);

$Query = "select name, parent,id from $tb WHERE level=2 order by id";
$r2 = myQuery($Query);

$sourceData = array();
$sourceLabel = array();

for ($i=0;$i<count($r);$i++){

	array_push($sourceData,$r[$i][1]);
	array_push($sourceLabel,$r[$i][0]);

	for ($n=0;$n<count($r1);$n++){

		if ($r[$i][1]==$r1[$n][1]){

			array_push($sourceData,$r1[$n][2]);
			array_push($sourceLabel,"-&nbsp;&nbsp;&nbsp;" . $r1[$n][0] );

			for ($m=0;$m<count($r2);$m++){

			if ($r1[$n][2]==$r2[$m][1]){

				array_push($sourceData,$r2[$m][2]);
				array_push($sourceLabel,"---&nbsp;&nbsp;&nbsp;" . $r2[$m][0] );

			}
			}

		}
	}

}

FFPSelectBox($boxName,$Category,$sourceData,$sourceLabel);

?>
                            </td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Weight :</td>
                            <td><input name="weight" type="text" class="text" id="weight" value="<?=$weight?>" size="8">
      Kg </td>
                            <td>Hide weight ? 
                            <input name="hideweight" type="checkbox" id="hideweight" value="1" <?=($hideweight?'checked':'')?>></td>
                          </tr>
                          <tr>
                            <td>Re-order :</td>
                            <td><input name="reorder" type="text" class="text" id="reorder" value="<?=$reorder?>" size="8"></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Current Stock Level:</td>
                            <td><input name="stock" type="text" class="text" id="stock" value="<?=$stock?>" size="8">
                            </td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Price : </td>
                            <td><input type="text" class="text" name="Euro" size="10"  value=<?print($Price_euro)?>  <?print($active)?>>
      Nomal<br>
      <input type="text" class="text" name="Gbp" size="10" value=<?print($Price_gbp)?>  <?print($active)?>>
      Special<br>
      <input type="text" class="text" name="Hkd" size="10" value=<?print($Price_hkd)?>  <?print($active)?>>
      Member<br>
      <input type="text" class="text" name="Usd" size="10" value=<?print($Price_usd)?>  <?print($active)?>>
      VIP<br>
                            </td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Issue Date: </td>
                            <td><?=inputDate($da,$mo,$ye)?>
      (dd-mm-yyyy) </td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Update Date: </td>
                            <td><?=inputDate($uda,$umo,$uye,'u')?>
      (dd-mm-yyyy) </td>
                            <td>&nbsp;</td>
                          </tr>
                        </table></td>
                      </tr>
                    </table>
                    <table width="95%" border="0" align="center">
                      <tr> 
      <td align="right">
	  
	  <input type="image" src="../../images/bt_cancel.gif" width="78" height="23" onclick="Redirect('product_menu.php?Start_Num=<?=$Start_Num?>',1);return false;"> 
      <input name="image" type="image" onClick="MM_validateForm('Code','','R','Name','','R','CName','','R','weight','','RisNum','reorder','','NisNum','stock','','NisNum','Euro','','RisNum','Gbp','','NisNum','Hkd','','NisNum','Usd','','NisNum');return document.MM_returnValue" src="../../images/bt_save.gif" width="76" height="22">
</td>
                      </tr>
                    </table>
                  </form>
            <!--Content End-->
            <?
require($rela_path . "inc/footer.php");
?>
        